<%@ page language="java" import="java.util.*" pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<% String path=request.getContextPath(); String basePath=request.getScheme()+ "://" + request.getServerName() + ":" + request.getServerPort() + path+ "/"; %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html xmlns="http://www.w3.org/1999/xhtml"> 
<head>
<base href="<%=basePath%>">
<title>险种添加</title>
<%@ include file="/WEB-INF/jsp/common/common.jsp" %>
<style type="text/css">
.input_text{
width: 250px;
}
.select_1{
width: 250px;
}
</style>
<script src="js/jquery.validate.js" type="text/javascript" ></script>
<script src="js/jquery.divbox.js" type="text/javascript"></script>
<script src="js/json2.js" type="text/javascript"></script>


<script type="text/javascript">
var startP=1;
var prodType='${prodType}';
var prodCode='${prodCode}';
var useRiskCode="";
var Formstatus=true;
var REG = /^[0-9]+.?[0-9]*$/;    

$(document).ready(function() {
	loadPlan({current:1,size:6,prodCode:prodCode});

});

function loadPlan(param){
	$.openLoading();
	$.ajax({
		url : "noCarProduct/loadPlan",
		type : 'POST',
		async : true,
		dataType:'json',
		data:param,
		success : function(page) {
// 			alert(JSON.stringify(page))
			$.closeLoading();
			if($.validate(page))return;
			startP = page.current;
			var buttonStr = "<a href='javascript:void(0)' onClick='editRiskReq(this);return false'>编辑</a>&nbsp;<a href='javascript:void(0)' onClick='delRisk(this)'>删除</a>";
			var tableContent = creatTable("riskCode@TDH,prodCode@TDH,nField1,riskName,riskCalType@TDH,riskCalDscp,amount,nField19,nfield6,nfield7,cField1@TDH,cField1Desc081F,cField10",page,buttonStr);
			var tableObj = $("#ProdPlanTable");
			tableObj.find("tbody").remove();
			tableObj.append(tableContent);
			var strPage = creatChannelPage3(startP,6,page.maxPage,"13");
			var pageDIV = $("#ProdPlanpageDIV");
			pageDIV[0].innerHTML="";
			pageDIV.append(strPage);
		}
	});
}

function queryProdPlan(pagenum){
	loadPlan({current:pagenum,size:6,prodCode:prodCode});
}
function addRisk(param){
	if(!Formstatus){
		$.message("error","正在处理中");
		return;
	}
	Formstatus=false;
	$.openLoading();
	$.ajax({
		url : "noCarProduct/saveRisk",
		type : 'POST',
		async : true,
		dataType:'json',
		data:param,
		success : function(obj) {
			Formstatus=true;
			$.closeLoading();
			if($.validate(obj))return;
			vreset();
			loadPlan({current:1,size:6,prodCode:prodCode});
		}
	});
}

//添加险别校验
function add(){
	if($("#riskCode").val()==""){
		$.message("error","请选择险别");
    	return;
	}

	if($("#riskCalType").val()==""){
		$.message("error","请选择保费计算方式");
    	return;
	}
	
	if($("#airTicketType").val()==""){
		$.message("error","请选择机票类型");
    	return;
	}

	var Amount= $.trim($("#amount").val());
// 	if(Amount.length==0){
// 		$.message("error","请输入保险金额（元）");
//     	return;
// 	}
    //小数点. 后面只能保留2位小数
    var reg = new RegExp("^(([1-9][0-9]*)|0)(\.[0-9]{1,2})?$");
//     var flag= reg.test(Amount);
//     if(!flag){
//     	$.message("error","输入保险金额（元）最多保留2位小数");
//     	return;
//     }
    //没有小数点情况下，输入金额长度不能超过8位数字
//     var strval = Amount+"";
//     var idx = strval.indexOf('.');
//     if(idx==-1){
//     	if(strval.length>8){
//     		$.message("error","输入保险金额（元）长度不能超过8位数字");
//     		return;
//     	}
//     }

	var riskCode = $('#riskCode').val();
	var riskName = $('#riskCode').find("option:selected").text();
	var riskCalType= $("#riskCalType").val();
	var cField10= $("#cField10").val();
    var nField6=$("#n_field_6").val();
    var nField7=$("#n_field_7").val();
    var cField1=$("#airTicketType").val();
	var nField19= $("#nField19").val();
	var prmryFlag= $("#prmryFlag").val();
	if(nField6!=""&&nField6.length!=0){
    	if (!REG.test(nField6)) {  
	         alert("基准保费应该输入数字");  
	         return ; 
    	}
    }
	  if(nField7==""||nField7.length==0){
		  $.message("error","实际保费（元）不能是空");
		  return;
	  }else if (!REG.test(nField7)) {  
	         alert("实际保费应该输入数字");  
	         return ;  
	  }  
// 	  var flagnField7= reg.test(nField7);
	addRisk({prodType:prodType,prodCode:prodCode,riskCode:riskCode,riskName:riskName,riskCalType:riskCalType,amount:Amount,cField10:cField10,nField6:nField6,nField7:nField7,nField19:nField19,cField1:cField1,prmryFlag:prmryFlag});
}

/**
 * 重置
 */
function vreset(){
	$("#riskCode").val("");
	$("#riskCalType").val("");
	$("#amount").val("");
	$("#cField10").val("");
	$("#n_field_6").val("");
	$("#n_field_7").val("");
	$("#airTicketType").val("");
	$("#nField19").val("");
	$("#nField21").val("");
	
}
/**
 * 删除险种
 */
function delRisk(obj){
	var riskCode  = $(obj).parent('td').parent('tr')[0].childNodes[0].innerHTML;
	var indexId  =  $(obj).parent('td').parent('tr')[0].childNodes[2].innerHTML;

	$.dialog({
		type: "warn",//success,error
		content: "您确定要删除该险别吗？",
		onOk: function() {
			deleteRisk(prodCode,riskCode,indexId);
		}
	});
}
function deleteRisk(prodCode,riskCode,indexId){
	
	$.openLoading();
	$.ajax({
		url : "noCarProduct/riskDelete",
		type : 'POST',
		async : true,
		dataType:'json',
		data:{prodCode:prodCode,riskCode:riskCode,nField1:indexId},
		success : function(obj) {
			$.closeLoading();
			if($.validate(obj))return;
			
			loadPlan({current:1,size:6,prodCode:prodCode});
		}
	});
}
var nField1=0;
//打开编辑窗口，编辑“组合方案信息”
function editRiskReq(obj){
	var editTr = $(obj).parent('td').parent('tr')[0];
	var riskCode = editTr.childNodes[0].innerHTML;
	useRiskCode=riskCode;
	nField1 = editTr.childNodes[2].innerHTML;
	var riskName = editTr.childNodes[3].innerHTML;
	var riskCalType = editTr.childNodes[4].innerHTML;
// 	 alert("riskCode0:"+riskCode+"   nField12:"+nField1+"    riskName3:"+riskName+"    riskCalType4:"+riskCalType+"    qq5: "+qq)
	var amount = editTr.childNodes[6].innerHTML;
	var nField19 = editTr.childNodes[7].innerHTML;
    var nField6=editTr.childNodes[8].innerHTML;
    var nField7=editTr.childNodes[9].innerHTML;
    var cField1=editTr.childNodes[10].innerHTML;
	var cField10 = editTr.childNodes[12].innerHTML;
// 	"riskCode@TDH,prodCode@TDH,nField1,riskName,riskCalType@TDH,riskCalDscp,amount,nField19,nfield6,nfield7,cField1@TDH,cField1Desc081F,cField10",page,buttonStr);
	//$("#eriskCode").val(riskCode);
	$("#eriskName").val(riskName);
	$("#eamount").val(amount);
	$("#ecField10").val(cField10);
	$("#enField19").val(nField19);
    $("#en_field_6").val(nField6);
    $("#en_field_7").val(nField7);
    $("#eairTicketType").val(cField1);
	$("#eriskCalType").val(riskCalType);
	
	$("#editPlanDiv").OpenDiv();
}

function saveEditRisk(){
    
	if($("#eriskCalType").val()==""){
		$.message("error","请选择保费计算方式");
    	return;
	}
	if($("#eairTicketType").val()==""){
		$.message("error","请选择机票类型");
    	return;
	}

	var Amount= $.trim($("#eamount").val());
// 	if(Amount.length==0){
// 		$.message("error","请输入保险金额（元）");
//     	return;
// 	}
    //小数点. 后面只能保留2位小数
    var reg = new RegExp("^(([1-9][0-9]*)|0)(\.[0-9]{1,2})?$");
//     var flag= reg.test(Amount);
//     if(!flag){
//     	$.message("error","输入保险金额（元）最多保留2位小数");
//     	return;
//     }
    //没有小数点情况下，输入金额长度不能超过8位数字
    var strval = Amount+"";
//     var idx = strval.indexOf('.');
//     if(idx==-1){
//     	if(strval.length>8){
//     		$.message("error","输入保险金额（元）长度不能超过8位数字");
//     		return;
//     	}
//     }
	var amount = $('#eamount').val();
	var riskCalType= $("#eriskCalType").val();
	var cField10= $("#ecField10").val();
	var nField19= $("#enField19").val();
    var nField6=$("#en_field_6").val();
    var nField7=$("#en_field_7").val();
    var cField1=$("#eairTicketType").val();
    if(nField6!=""&&nField6.length!=0){
    	if (!REG.test(nField6)) {  
	         alert("基准保费应该输入数字");  
	         return ; 
    	}
    }
    if(nField7==""||nField7.length==0){
		  $.message("error","实际保费（元）不能是空");
		  return;
	  }else if (!REG.test(nField7)) {  
	         alert("实际保费应该输入数字");  
	         return ;  
	  }  
	updateRiskInfo({prodType:prodType,prodCode:prodCode,riskCode:useRiskCode,amount:amount,riskCalType:riskCalType,cField10:cField10,nField19:nField19,nField6:nField6,nField7:nField7,nField1:nField1,cField1:cField1});
}


function updateRiskInfo(param){
	if(!Formstatus){
		$.message("error", "正在处理中");
		return;
	}
	Formstatus=false;
	$.openLoading();
	$.ajax({
		url : "noCarProduct/riskUpdate",
		type : 'POST',
		async : true,
		dataType:'json',
		data:param,
		success : function(obj) {
			Formstatus=true;
			$.closeLoading();
			if($.validate(obj))return;
			loadPlan({current:1,size:6,prodCode:prodCode});
			closeEditPlanDiv();
		}
	});
}
function addMainSign(){
	var otherCode=$('#riskCode :selected').attr('class');
	if(otherCode==0){
		$("#nField21").val('主险');
		$("#prmryFlag").val('0');
	}else if(otherCode==1){
		$("#nField21").val('附加险');
		$("#prmryFlag").val('1');
	}else{
		$("#nField21").val('');
		$("#prmryFlag").val('');
	}
}

function closeEditPlanDiv(){
	$("#editPlanDiv").CloseDiv();
}
</script>
<style>
	.input_text {
	padding-left: 3px;
	}
	</style>
</head>
<body>
<div class="right">
	      <div class="current">
	           <table class="current_table_1">
	              <tbody>
		              <tr>
		                <td><img src="./images/current_1.jpg"></td>
		                  <td class="current_table_1_td"><img src="images/current_1.png">&nbsp;您现在的位置：&nbsp;
			                  <span style=" color:#136bab; ">财险产品管理
			                  <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>产品配置
			                  <span style="padding:0 5px; font-weight:bold; line-height:28px;">&gt;</span>添加险别
			                  </span>
		                  </td>
		                  <td><img src="./images/current_3.jpg"></td>
		              </tr>
	           	  </tbody>
	           </table>
	      </div>
	      <div>
			<form id="inputForm" >
			<table class="table_05">
	              <tbody>
		    		  <tr>
 		              	<td style="line-height:23px;">
 		              		<font color="#3876bf"><b>产品代码：</b></font> ${prodCode}&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<font color="#3876bf"><b>产品名称：</b></font>${prodName}
 		              	</td>
		              </tr>
	           	  </tbody>
	         </table> 
	        <table class="table_05">
	              <tbody>
		              <tr>
		                  <td colspan="4" style=" font-size:12px; font-weight:bold; text-align:left;color:#3876bf; line-height:17px; background-image:url(images/centent_1.jpg)">险别添加</td>
		              </tr>
		    		  <tr>
		                  <th width="35%">险别：</th>
		                  <td width="18%"><select id="riskCode" name = "riskCode" class="select_1" style="visibility: visible;"onchange="addMainSign()">
		                  					<option value="">------------------请选择------------------</option>
		                  					<c:forEach var ="riskCode" items="${riskCode}">
		                  						<option id="riskCode" class="${riskCode.otherCode}" value="${riskCode.code}">${riskCode.codeName}</option>
		                  					</c:forEach>
		                  				  </select><span class="red">*</span>
		                   </td>
		                   <th width="30%">保费计算方式：</th>
		                  <td width="17%"><select id="riskCalType" name = "riskCalType" class="select_1" style="visibility: visible;">
		                  					<option value="">------------------请选择------------------</option>
		                  					<c:forEach var ="riskTypeCal" items="${riskCalTypeList}">
		                  						<option value="${riskTypeCal.code}">${riskTypeCal.codeName}</option>
		                  					</c:forEach>
		                  				  </select><span class="red">*</span></td>
		              </tr>
		              <tr>
		              	  <th width="35%">保险金额（元）：</th>
		                  <td width="18%"><input id="amount" name = "amount" type="text" maxlength="20" class="input_text" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
		                  <th width="30%">调整系数：</th>
		                  <td width="17%" ><input id="nField19" name = "nField19" type="text" maxlength="20" class="input_text" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
		              </tr>
		              <tr>
		              	  <th width="35%">基准保费（元）：</th>
		                  <td width="18%"><input id="n_field_6" name = "n_field_6"  type="text" maxlength="20" class="input_text" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
		                  <th width="30%">实际保费（元）：</th>
		                  <td width="17%"><input id="n_field_7" name = "n_field_7"  type="text" maxlength="20" class="input_text" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"><span class="red">*</span></td>
		              </tr>
		              <tr>
		                   <th width="35%" >机票类型：</th>
		                   <td width="18%">
		                       <select id="airTicketType" name = "airTicketType" class="select_1" style="visibility: visible;">
		                  					<option value="">------------------请选择------------------</option>
		                  					<c:forEach var ="insureItem081FList"  items="${insureItem081FList}">
		                  						<option value="${insureItem081FList.code}">${insureItem081FList.codeName}</option>
		                  					</c:forEach>
		                  		</select><span class="red">*</span>
		                   </td>
		                   <th width="30%">主附险标志：</th>
		                  <td width="17%"><input id="nField21" name = "nField21" type="text" maxlength="13" class="input_text" onKeyUp="clearNoNum(event,this)" readonly="true" style=" background-color: #ccc;" onBlur="checkNum(this)"><span class="red">*</span></td>
		                  
		              </tr>
		              <td colspan="1" ><input id="prmryFlag" name = "prmryFlag"  type="text" maxlength="20" class="input_text" style="display: none"  > </td>
		              <tr>
		                  <th width="35%">免赔条件：</th>
		                  <td colspan="3"><textarea name="cField10" id="cField10"  maxlength="500"  rows="5" class="textarea_1" style="resize:none"></textarea></td>
		              </tr>
	           	  </tbody>
	         </table> 
	         <div align="center">
	             <input class="input_button_1" name="" type="button" onclick="add()" value="保存">&nbsp;&nbsp;
		         <input class="input_button_1" name="" type="button" onclick="vreset()"value="重置">
	         </div>
	         </form>
	      </div>
	      
 	      <!-- 险别列表 -->
	      <div style="margin-top: 5px;">
	         <table class="table_02" id="ProdPlan" align="center" >
				<tbody>
					<tr>
						   <td colspan="6" style=" font-size:12px; font-weight:bold; text-align:left;color:#3876bf; line-height:27px;height:27px; background-image:url(images/centent_1.jpg)">&nbsp;已添加险别列表</td>
					</tr>
					<tr>
						<td>
							<table id="ProdPlanTable" class="content_table_1">
								<thead>
									<tr class="f1">
									   <th style="width:5%">序号</th>
									   <th style="width:11%">险别</th>
					                   <th style="width:11%">保费计算方式</th>
								       <th style="width:11%">保险金额（元）</th>
								       <th style="width:11%">调整系数</th>
								       <th style="width:11%">基准保费（元）</th>
								       <th style="width:11%">实际保费（元）</th>
								       <th style="width:11%">机票类型</th>
								       <th style="width:11%">免赔条件</th>
								       <th style="width:7%">操作</th>
					              	</tr>
								</thead>
								<tbody>
								</tbody>
							</table>
							<div id="ProdPlanpageDIV"  class="page"></div>
						</td>
					</tr>
				</tbody>
			</table>
	      </div>     
	

</div>
	<!--   	添加模板 DIV 默认隐藏-->
	<div id="editPlanDiv"  style="display:none;overflow-y:auto; width:60%">
			<input type="hidden" id="row_num" name="row_num" value="0"/>
			<div class="table_title_div">
					<table class="table_title" style='width:100%;height: 20px;'>
						<tr>
						<td width="10%"></td>
						<td width="80%" id="interfaceName"></td>
						<td width="10%" align="right"><img src="/manager/images/closedown.gif" alt="关闭"  onclick="closeEditPlanDiv()"/></td>
						</tr>
					</table>
			</div>
			<!-- 修改id 名 -->
			<table class="table_02"  id="addtempletTable" align="center">
				<tbody>
					<tr>
						<td>
							<table id="coverageTable"  class="content_table_1" style="height:120px;">
								
								<tbody>
									<tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">险别：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input type="text" id="eriskName" class="input_text"  readonly="readonly" style=" background-color: #ccc;"></td>
					                </tr>
					                <tr>
					                  <td width="40%" style="text-align:right;border-right:0px;">保费计算方式：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><select id="eriskCalType" class="select_1" style="visibility: visible;width:250px;">
		                  					<option value="">------------------请选择------------------</option>
		                  					<c:forEach var ="eriskTypeCal" items="${riskCalTypeList}">
		                  						<option value="${eriskTypeCal.code}">${eriskTypeCal.codeName}</option>
		                  					</c:forEach>
		                  				  </select><span class="red">*</span></td>
					                </tr>
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">保险金额（元）：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input id="eamount" type="text" class="input_text"  maxlength="20" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
					                </tr>
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">调整系数：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input id="enField19" type="text" class="input_text" maxlength="20" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
					                </tr>
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">基准保费（元）：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input id="en_field_6" type="text" class="input_text" maxlength="20" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"></td>
					                </tr>
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">实际保费（元）：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><input id="en_field_7" type="text" class="input_text" maxlength="20" onKeyUp="clearNoNum(event,this)" onBlur="checkNum(this)"><span class="red">*</span></td>
					                </tr>
					                  <tr>
						                   <td width="40%" style="text-align:right;border-right:0px;">机票类型：</td>
						                   <td width="60%" style="text-align:left">
						                       <select id="eairTicketType" name = "eairTicketType" class="select_1" style="visibility: visible;">
						                  					<option value="">------------------请选择------------------</option>
						                  					<c:forEach var ="insureItem081FList"  items="${insureItem081FList}">
						                  						<option value="${insureItem081FList.code}">${insureItem081FList.codeName}</option>
						                  					</c:forEach>
						                  		</select><span class="red">*</span>
						                   </td>
					             	 </tr>
					             	 
					                <tr>  
					                  <td width="40%" style="text-align:right;border-right:0px;">免赔条件：&nbsp;&nbsp;</td>
					                  <td width="60%" style="text-align:left"><textarea id="ecField10"  maxlength="500"  rows="5" class="textarea_1" style="resize:none;width: 250px"></textarea></td>
					                </tr>
								</tbody>
							</table>
							
						</td>
					</tr>
				</tbody>
			</table>
			<div align="center" >
			   <input class="input_button_3" name="" type="button" onclick="saveEditRisk()" value="保存">&nbsp;&nbsp;
	           <input class="input_button_3" name="" type="button" onclick="closeEditPlanDiv()" value="取消">
			</div>
	</div>
	
</body>
</html>